﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSConsoleTest
{
    class TestEvent : BaseConsoleTest
    {
        public void printDescription()
        {
            Console.WriteLine("--- Event ---");
        }

        public void doTest()
        {
            MockView mockView = new MockView();
            mockView.OnClickListener += onClick;

            mockView.click();
        }

        private void onClick(MockView view)
        {
            Console.WriteLine("Mock view clicked.");
        }
    }

    delegate void EventHandler(MockView view);

    class MockView
    {
        private event EventHandler mOnClickListener;

        public event EventHandler OnClickListener
        {
            add
            {
                mOnClickListener += value;
            }

            remove
            {
                mOnClickListener -= value;
            }
        }

        public void click()
        {
            if (mOnClickListener != null)
                mOnClickListener(this);
        }
    }
}
